//
// Created by feng on 19-3-28.
// PS: Define the grid data structure.
//

/*
为避免与util中的Grid重复，这里改为CudaGrid

    这里定义的是一整个要设置网格的区域，【pos_】是这块区域的中心点，【size_】是这块区域的大小，[interval_]是隔多远一个格子-也可以理解为格子的大小
    Grid类中还没有定义三个方向上各有多少个格子，只定义了要划分成网格的区域（在子类中再确定格子的个数）
    这块区域中只有一个接收器，其id为【belonging_receiver_index_】
            有[num_helios_】个定日镜,定日镜id从[start_helio_index_]开始，类型为[helio_type_]
*/

#ifndef SOLARENERGY_CHIER_GRID_CUH
#define SOLARENERGY_CHIER_GRID_CUH

#include <cuda.h>
#include <cuda_runtime.h>

#include <vector>

#include <algorithm/rayTracing/rayTracingDataStructure/heliostat/CudaHeliostat.cuh>

namespace solar::cuda
{
    class CudaGrid
    {
        public:
            virtual ~CudaGrid() = default;
            __device__ __host__ CudaGrid() = default;
            virtual void Cinit() = 0;
            virtual void CClear() = 0;
            // Set *d_grid_helio_match_, *d_grid_helio_index_ and num_grid_helio_match_
            virtual auto CGridHelioMatch(const std::vector<CudaHeliostat*>& h_helios) -> int = 0;

            /**
             * Getters and setters of attributes for Grid object.
             */
            auto getGridType() const -> int;
            void setGridType(int type_);

            __device__ __host__ auto getPosition() const -> float3 { return pos_; }
            void setPosition(float3 pos_);

            [[nodiscard]] auto getSize() const -> float3;
            void setSize(float3 size_);

            __device__ __host__ auto getInterval() const -> float3 { return interval_; }
            void setInterval(float3 interval_);

            [[nodiscard]] auto getHeliostatType() const -> int;
            void setHeliostatType(int helio_type_);

            [[nodiscard]] auto getStartHeliostatIndex() const -> int;
            void setStartHeliostatIndex(int start_helio_index_);

            [[nodiscard]] auto getNumberOfHeliostats() const -> int;
            void setNumberOfHeliostats(int num_helios_);

            [[nodiscard]] auto getBelongingReceiverIndex() const -> int;
            void setBelongingReceiverIndex(int belonging_receiver_index_);

            void test();

            int type_; // RectangleGrid : 0  ... ... // 网格类型
            float3 pos_;
            float3 size_;
            float3 interval_; // 间隔？？？

            int helio_type_;        // 定日镜类型
            int start_helio_index_; // The first heliostat index of the heliostat lists in this grid
            int num_helios_;        // The number of heliostats in this grid 定日镜个数
            int belonging_receiver_index_; // 一个grid对应一个receiver吗？？？
    };
} // namespace solar::cuda

#endif // SOLARENERGY_CHIER_GRID_CUH
